package  
{
	import org.flixel.FlxG;
	import org.flixel.FlxObject;
	import org.flixel.FlxPoint;
	import org.flixel.FlxSprite;
	import org.flixel.FlxText;
	/**
	 * ...
	 * @author João Brant
	 */
	public class HUD extends FlxObject
	{
		private var state:MainState;
		
		private var money:FlxText;
		private var moneyPosition:FlxPoint;
		
		private var itemEquipavel1Borda:FlxSprite;
		private var itemEquipavel2Borda:FlxSprite;
		private var itemEquipavel1:FlxSprite;
		private var itemEquipavel2:FlxSprite;
		private var itemEquipavelPosition:FlxPoint;
		
		private var timeLeft:FlxText;
		private var timeLeftExplaination:FlxText;
		private var timeLeftPosition:FlxPoint;
		
		private var popularity:FlxText;
		private var popularityPosition:FlxPoint;
		
		public function HUD(state:MainState) 
		{
			this.state = state;
			
			itemEquipavel1Borda = new FlxSprite;
			itemEquipavel2Borda = new FlxSprite;
			itemEquipavel1 = new FlxSprite;
			itemEquipavel2 = new FlxSprite;
			itemEquipavelPosition = new FlxPoint(Main.windowWidth-100, 40);
			
			money = new FlxText(-100, -100, 200, "$");
			money.setFormat(null, 15);
			moneyPosition = new FlxPoint(10, 10);
			popularity = new FlxText(-100, -100, 300, "%");
			popularity.setFormat(null, 15);
			popularityPosition = new FlxPoint(Main.windowWidth - 160, 10);
			timeLeft = new FlxText(-100,-100,100);
			timeLeft.setFormat(null, 20);
			timeLeftExplaination = new FlxText(-100,-100,300);
			timeLeftExplaination.setFormat(null, 15);
			timeLeftPosition = new FlxPoint(Main.windowWidth/2 - 100,10);
		}
		
		public override function update():void
		{
			this.x = FlxG.camera.scroll.x;
			this.y = FlxG.camera.scroll.y;
			
			money.update();
			popularity.update();
			timeLeft.update();
			timeLeftExplaination.update();
			
			money.text = "Mandate money\n $" + new int(state.MoneyAmount);
			popularity.text = "Popularity: " + new int(state.popularity) + "%";
			timeLeftExplaination.text = "Time to finish, " + PlayerData.levelNames[PlayerData.level] + ":";
			timeLeft.text = new String(new int(state.timeLeft));
			if (state.timeLeft < 11)
			{
				timeLeft.setFormat(null, 30);
			}
			
			itemEquipavel1Borda.x = this.x + itemEquipavelPosition.x;
			itemEquipavel1Borda.y = this.y + itemEquipavelPosition.y;
			itemEquipavel2Borda.x = this.x + itemEquipavelPosition.x + itemEquipavel1Borda.width;
			itemEquipavel2Borda.y = this.y + itemEquipavelPosition.y;
			itemEquipavel1.x = itemEquipavel1Borda.x;
			itemEquipavel1.y = itemEquipavel1Borda.y;
			itemEquipavel2.x = itemEquipavel2Borda.x;
			itemEquipavel2.y = itemEquipavel2Borda.y;
			
			money.x = this.x + moneyPosition.x;
			money.y = this.y + moneyPosition.y;
			popularity.x = this.x + popularityPosition.x;
			popularity.y = this.y + popularityPosition.y;
			timeLeftExplaination.x = this.x + timeLeftPosition.x;
			timeLeftExplaination.y = this.y + timeLeftPosition.y;
			timeLeft.x = timeLeftExplaination.x + 90;
			timeLeft.y = timeLeftExplaination.y + 30;
			
			super.update();
		}
		
		public override function draw():void
		{
			money.draw();
			popularity.draw();
			timeLeft.draw();
			timeLeftExplaination.draw();
			//itemEquipavel1Borda.draw();
			//itemEquipavel2Borda.draw();
			//itemEquipavel1.draw();
			//itemEquipavel2.draw();
			super.draw();
			
		}
		
	}

}